package com.example.art.chapter3.one.one_four

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.GestureDetector
import android.view.MotionEvent
import com.example.art.R


/**
 * Created by 舍长
 * describe:
 */
class SimpleOnGestureListenerActivity : AppCompatActivity() {

    private var mDector: GestureDetector? = null

    private var mgListener: SimpleOnGestureListener? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_simple_on_gesture_listener)
        mgListener= SimpleOnGestureListener()
        mDector= GestureDetector(this,mgListener)
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        return mDector!!.onTouchEvent(event)
    }

    inner class SimpleOnGestureListener: GestureDetector.SimpleOnGestureListener() {

        private var min_move = 200//滑动的最小距离

        override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
            Log.d("hello","onFling")
            if(e1.y-e2.y>min_move){
                val intent=Intent(this@SimpleOnGestureListenerActivity,
                    GestureActivity::class.java)
                startActivity(intent)
            }else if(e1.y-e2.y<min_move){
                finish()
            }
            return true
        }
    }

}

